/*
 *	Resource Properties Class
 *  		1997/10/13 (C) Copyright T.Kazawa (Digitune)
 */

package com.file.transfers.util;

import java.util.Properties;
import java.util.ResourceBundle;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.MissingResourceException;

public class ResourceProperties extends Properties {
	private Properties properties = null;
	public ResourceProperties(String file){
		init(file);
	}
//    ResourceBundle rc = null;
//
//    public String getProperty(String key, String defaultVal) {
//	String val = getProperty(key);
//	return (val == null) ? defaultVal : val;
//    }
//
//    public ResourceProperties() {
//	this(null);
//    }
//
//    public ResourceProperties(String r) {
//	try {
//	    rc = ResourceBundle.getBundle(r);
//	} catch (MissingResourceException ex) {
//	    rc = null;
//	}
//    }
//
//    public String getProperty(String key)
//	throws MissingResourceException {
//	String val = (String)super.get(key);
//	return ((val == null) && (rc != null)) ? rc.getString(key) : val;
//    }
	public  void init(String file){
		try {
			properties = new Properties(); 
			FileInputStream filein = new FileInputStream(file);
			properties.load(filein);
			filein.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public String  getString(String key){
		return ((key != null) && (properties != null)) ? properties.getProperty(key) : null;
	}
	public int  getInt(String key){
		if((key != null) && (properties != null)){
			String property = properties.getProperty(key);
			int parseInt = Integer.parseInt(property);
			return parseInt;
		}else{
			return 8888;
		}
	}
	public Object  getObject(String key){
		return ((key != null) && (properties != null)) ? properties.getProperty(key) : null;
	}
}
